﻿<Serializable()>
Public Class ProjectElementEditor


    Private LinkedElementValue As L3DObjectsLibrary.ProjectElement
    Public Event CloseRequest(ByVal sender As Object, ByVal CloseStatus As Microsoft.VisualBasic.MsgBoxResult)
    Public Property LinkedElement As L3DObjectsLibrary.ProjectElement
        Get
            Return LinkedElementValue
        End Get
        Set(ByVal value As L3DObjectsLibrary.ProjectElement)
            LinkedElementValue = value
            FillFromLinkedProjectElement()
        End Set
    End Property
    Private Sub FillFromLinkedProjectElement()
        txtName.Text = LinkedElement.Name
        txtName.Focus()
        txtName.SelectAll()
    End Sub
    Private Sub ControlsHandlersAdd(ByVal Father As Object)
        For Each Control As Windows.Forms.Control In Father.Controls
            If Control.HasChildren = True Then
                ControlsHandlersAdd(Control)
            End If
            If Control.GetType = GetType(Windows.Forms.TextBox) _
                    Or Control.GetType = GetType(Windows.Forms.DateTimePicker) _
                    Or Control.GetType = GetType(Windows.Forms.ComboBox) _
                    Or Control.GetType = GetType(Windows.Forms.NumericUpDown) _
                    Or Control.GetType = GetType(Windows.Forms.CheckBox) Then
                AddHandler Control.KeyUp, AddressOf Key_UP
            End If
        Next
    End Sub
    Private Sub Key_UP(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            cmdOK.PerformClick()
        ElseIf e.KeyCode = Windows.Forms.Keys.Escape Then
            cmdCancel.PerformClick()
        End If
    End Sub
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Ok)
        LinkedElement.Name = txtName.Text
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Cancel)
    End Sub
    Private Sub ProjectElementEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ControlsHandlersAdd(Me)
    End Sub
    Private Sub ProjectElementEditor_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As System.Drawing.Graphics = e.Graphics
        Dim Rect As New System.Drawing.Rectangle(1, 1, Me.Width - 3, Me.Height - 3)
        Dim MyPen As New System.Drawing.Pen(New System.Drawing.SolidBrush(Drawing.ColorTranslator.FromHtml("#000000")), 1)
        g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
        VMGenLibrary.Graphics.DrawRoundedRectangle(g, MyPen, Rect, New System.Drawing.Size(20, 20), Drawing.ColorTranslator.FromHtml("#FFFFC0"))
    End Sub
End Class
